package com.example.xjtuse_pc.utils;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

/**
 * Created by PC on 2016-4-6.
 */
public class SeviceUtils {
    /**
     * 检查服务是否存活着
     * @param context
     * @param servicename
     * @return
     */

    public static boolean isServiceRunning(Context context,String servicename){
        ActivityManager am= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> infos=am.getRunningServices(20);
        for(ActivityManager.RunningServiceInfo info:infos){
           String ServiceName= info.service.getClassName();
            if(ServiceName.equals(servicename)){
                return true;
            }
        }

    return false;
    }
}
